
export function getDay(day){ // 获取N天内的时间
  var today = new Date();
  let doHandleMonth = (month)=> {
    var m = month;
    if (month.toString().length == 1) {
      m = "0" + month;
    }
    return m;
  }
  var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
  today.setTime(targetday_milliseconds);
  var tYear = today.getFullYear();
  var tMonth = today.getMonth();
  var tDate = today.getDate();
  tMonth = doHandleMonth(tMonth + 1);
  tDate = doHandleMonth(tDate);
  return tYear+"-"+tMonth+"-"+tDate;
}
export function parseMoney(s, n) { // 输入框金额
  if (!s) return '0.00'
  n = n > 0 && n <= 20 ? n : 2
  s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(n) + ''
  const l = s.split('.')[0].split('').reverse()
  const r = s.split('.')[1]
  let t = ''
  for (let i = 0; i < l.length; i++) {
    t += l[i] + ((i + 1) % 3 === 0 && (i + 1) !== l.length ? '' : '')
  }
  return t.split('').reverse().join('') + '.' + r
}
export function paySatus(type) { // 支付信息
  if (type || type === 0) {
    const patStatus = [
      { pt: 'ALIPAY_APP', wm: '0', value: '支付宝【APP】' },
      { pt: 'WXPAY_APP', wm: '1', value: '微信【APP】' },
      { pt: 'BALANCE', wm: '2', value: '余额' },
      { pt: 'WXPAY_PUBLIC', wm: '3', value: '微信【公众号】' },
      { pt: 'WXPAY_MINI', wm: '4', value: '微信【小程序】' },
      { pt: 'WXPAY_MINI_NEW', wm: '5', value: '微信【小程序】' },
      { pt: 'WXPAY_H5', wm: '6', value: '微信【web】' },
      { pt: 'ALIPAY_WAP', wm: '7', value: '支付宝【web】' }
    ]
    const index = patStatus.findIndex(i => i.wm == type || i.pt == type)
    return  index > -1 ? patStatus[index].value : '未知'
  } else {
    return '未知'
  }
}
export function toTimeForHs(str) {  // 后台所要23：59：59转换成24:00点
  if (str) {
    const arr = str.split(',')
    return [arr[0].slice(0,5),arr[1] === '23:59:59' || arr[1] =='23:59'? '24:00' :arr[1].slice(0,5)]
  } else {
    return []
  }
}
export function toTimeForYHs(time) { // 24点转换成后台所学23：59：59
  if (time.length && time[0] && time[1]) {
    return [`${time[0]}:00`,time[1] == '24:00' ?'23:59:59':`${time[1]}:00`].join(',')
  } else {
    return ''
  }
}
